//go:build windows

package progressbar

import (
	"golang.org/x/sys/windows"
)

func (p *Progressbar) getTerminalSize() int {
	handle, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE)
	if err != nil {
		return _DEFAULT_TERMINAL_SIZE
	}

	var mode uint32
	if err := windows.GetConsoleMode(handle, &mode); err != nil {
	}

	var consoleInfo windows.ConsoleScreenBufferInfo
	if err = windows.GetConsoleScreenBufferInfo(handle, &consoleInfo); err != nil {
		return _DEFAULT_TERMINAL_SIZE
	}

	return int(consoleInfo.Window.Right - consoleInfo.Window.Left + 1)
}
